package com.itheima.idea.tist;

import com.itheima.idea.demain.Student;

import java.util.ArrayList;

public class Test2 {
    public static void main(String[] args) {
        //2.创建集合对象,当泛型是一个类名时,未来集合中要存储的是该类的对象
        ArrayList<Student> list = new ArrayList<>();
        //3.创建学生对象
        Student stu1 = new Student("张三",23);
        Student stu2 = new Student("张三1",23);
        Student stu3 = new Student("张三2",23);
        //4.添加学生对象到集合中
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        //5.遍历集合,采用通用遍历格式实现
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu.getName() +"....." + stu.getAge());
        }
    }
}
